<template>
	<view>
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">养殖仓编号</view>
				<input maxlength="10" v-model="WarehouseNo" placeholder="请输入编号" name="input" style="text-align: right; margin-right: 58rpx;"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">养殖仓面积</view>
				<input maxlength="6" v-model="area" class="area" type="digit" placeholder="请输入面积" name="input" style="text-align: right; margin-right: 20rpx;"></input>
				<text style="font-size: 34rpx;">m²</text>
			</view>
			<view class="cu-form-group">
				<view class="title">养殖仓数量</view>
				<input maxlength="8" v-model="count" class="count" type="number" placeholder="请输入数量" name="input" style="text-align: right; margin-right: 20rpx;"></input>
				<text style="font-size: 34rpx; margin-right: 10rpx;">头</text>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">养殖仓负责人</view>
				<input maxlength="6" v-model="adminName" placeholder="请输入负责人" name="input" style="text-align: right; margin-right: 20rpx;"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">负责人联系电话</view>
				<input maxlength="11" type="number" v-model="phone" placeholder="请输入联系电话" name="input" style="text-align: right; margin-right: 20rpx;"></input>
			</view>
		</form>
	</view>
</template>

<script>
	import User from "../../../common/user.js"
	export default {
		data () {
			return {
				WarehouseNo: '',
				area: '',
				count: '',
				phone: '',
				adminName: ''
			}
		},
		onNavigationBarButtonTap() {
			this.submit()
		},
		methods: {
			submit () {
				console.log(this.User.token)
				var mobileReg=/^1[34578]\d{9}$/
				//console.log(this.User.token)
				if(this.WarehouseNo.toString() === ""){
					uni.showToast({
						title:"请填写正确的养殖仓编号",
						icon: "none"
					})
					return;
				}
				else if(this.area.toString() === "" || this.area <= 0){
					uni.showToast({
						title:"请填写正确的养殖仓面积",
						icon: "none"
					})
					return;
				}
				else if(this.count.toString().indexOf(".") !== -1 || this.count.toString() === ""){
					uni.showToast({
						title:"请填写正确的养殖仓数量（不能含有小数）",
						icon: "none"
					})
					return;
				}
				else if(this.adminName.toString() === ""){
					uni.showToast({
						title:"请输入养殖仓负责人",
						icon: "none"
					})
					return;
				}
				else if(!mobileReg.test(this.phone)){
					uni.showToast({
						title:"请填写正确的负责人联系电话",
						icon: "none"
					})
					return;
				}
				else{
					uni.request({
						url: this.confige.webUrl+'/livestock/addSys_Warehouse',
						data: {
							warehouse_serial_number: this.WarehouseNo,
							warehouse_area: this.area,
							warehouse_number: this.count,
							warehouse_phone: this.phone,
							warehouse_admin_name: this.adminName,
							farm_id: this.User.userInfo.farm_id,
							farm_name: this.User.userInfo.farm_name,
							warehouse_faeces_id: 99,
							warehouse_faeces_id: 100
						},
						method:"POST",
						header: {
							"X-Token":this.User.token
						},
						success: (res) => {
							console.log(res)
							if(res.data.code == 200){
								uni.showModal({
									title: "提示",
									showCancel: false,
									content: "登记成功",
									success: (res) => {
										if(res.confirm){
											uni.navigateBack({
												delta: 1
											})
										}
									}
								})	
							}
							else if(res.data.code == 400) {
								uni.showModal({
									title: "提示",
									showCancel: false,
									content: res.data.message
								})
							}
						}
						
					})
					console.log('手机：' + this.phone+'--负责人：' + this.adminName+'--编号：' +this.WarehouseNo+'--数量：' +this.count+'--面积：' +this.area)
				}	
			}
		}
	}
</script>

<style lang="less">
	@import '../../../common/main.css';
	
	page {
		background: #EEEEEE;
	}
	
	.submit {
		width: 710rpx;
		height: 80rpx;
		position: fixed;
		bottom: 30rpx;
	}
	
	.submit button {
		background-color: #4AC997;
		color: white;
		font-weight: bold;
		border-radius: 60rpx;
		margin-left: 40rpx;
		height: 80rpx;
	}
</style>
